package com.emmy.walnut.ui;

import android.app.Dialog;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.emmy.walnut.R;

/**
 * @ClassName TextDialog
 * @Description TODO
 * @Author zhouxuan
 * @Date 2020/02/14 18:47
 * @Version 1.0
 */
public class EditTextDialog extends Dialog {

    private Button cancelButton;
    private Button confirmButton;
    private EditText editText;
    private Context context;
    private OnClickListener onClickListener;

    public EditTextDialog(Context context){
        super(context, R.style.DialogBackgroundNull);
    }

    public EditTextDialog(Context context, int resThemeId){
        super(context, resThemeId);
        this.context = context;
    }

    public interface OnClickListener{
        void onCancelListener();
        void onConfirmListener();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_edittext_layout);
        editText = findViewById(R.id.dialog_edit_text);
        cancelButton = findViewById(R.id.dialog_cancel_button);
        confirmButton = findViewById(R.id.dialog_confirm_button);
        cancelButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onClickListener!=null) {
                    onClickListener.onCancelListener();
                }
            }
        });
        confirmButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onClickListener!=null) {
                    onClickListener.onConfirmListener();
                }
            }
        });
    }

    public void setOnClickListener(final OnClickListener onClickListener){
        if (onClickListener!=null){
            this.onClickListener = onClickListener;
        }
    }

    public EditText getEditText() {
        return editText;
    }
}
